import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

public class ButtonActionPanel extends JPanel {

	/**
	 * 
	 */
	private JButton m_rollDice, m_viewDealCards, m_viewMailCards, m_viewLoans, m_quit;
	private static final long serialVersionUID = 1L;
	private static ButtonActionPanel ref;

	private ActionListener getRollDiceListener() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO add event handler for rolling dice, maybe open up a new
				// window and show animation or show it on the main game panel
				// frame (where the board is)

			}
		};
	}

	private ActionListener getViewDealCardsListener() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO add event handler for viewing deal cards, maybe open up
				// a new window to show list (make user autofocus onto window)

			}
		};
	}

	private ActionListener getViewLoansListener() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO add event handler for viewing loans (similar to deal cards)
				// maybe add function to pay off loan

			}
		};
	}

	private ActionListener getQuitListener() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO handle more properly by ending the game loop, or asking
				// if they are sure they want to quit
				System.exit(0);
			}
		};
	}
	private ActionListener getViewMailListener() {
		return new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO handle more properly by ending the game loop, or asking
				// if they are sure they want to quit
				System.exit(0);
			}
		};
	}
	private ButtonActionPanel() {
		setName("ButtonActionPanel");
		setLayout(new GridLayout(5,1,10,10)); // TODO magic numbers
		m_rollDice = new JButton("Roll Dice");
		m_viewDealCards = new JButton("View Deal Cards");
		m_viewMailCards = new JButton("View Mail Cards");
		m_viewLoans = new JButton("View Loans");
		m_quit = new JButton("Quit");

		m_rollDice.addActionListener(getRollDiceListener());
		m_viewDealCards.addActionListener(getViewDealCardsListener());
		m_viewMailCards.addActionListener(getViewMailListener());
		m_viewLoans.addActionListener(getViewLoansListener());
		m_quit.addActionListener(getQuitListener());

		this.add(m_rollDice);
		this.add(m_viewDealCards);
		this.add(m_viewMailCards);
		this.add(m_viewLoans);
		this.add(m_quit);
	}

	public static ButtonActionPanel getInstance() {
		if (ref == null) {
			ref = new ButtonActionPanel();
		}
		return ref;
	}
}
